#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
    int* answer = (int*)malloc(sizeof(int) * numsSize);
    int* L = (int*)malloc(sizeof(int) * numsSize);
    int* R = (int*)malloc(sizeof(int) * numsSize);
    int i = 0;
    L[0] = 1;
    for (i = 1; i < numsSize; i++) {
        L[i] = nums[i - 1] * L[i - 1];
    }
    R[numsSize - 1] = 1;
    for (i = numsSize - 2; i >= 0; i--) {
        R[i] = nums[i + 1] * R[i + 1];
    }
    for (i = 0; i < numsSize; i++) {
        answer[i] = L[i] * R[i];
    }
    *returnSize = numsSize;
    return answer;
}
int main() {
    int nums[4] = { 1,2,3,4 };
    int n;
    int* p = productExceptSelf(nums, 4, &n);
    int i = 0;
    for (i = 0; i < n; i++) {
        printf("%d ", p[i]);
    }
    return 0;
}